<template>
  <div>
    <Header/>
    <Search :cities="cities"/>
    <List :hotCities="hotCities"
          :cities="cities"
          :letter="letter"/>
    <Alphabet
      :cities="cities"
      @change="handleChange"/>
  </div>
</template>

<script>
  import Header from './components/Header'
  import Search from './components/Search'
  import List from './components/List'
  import Alphabet from './components/Alphabet'

  import axios from 'axios'


  export default {
    name: 'City',
    components: {
      Header,
      Search,
      List,
      Alphabet
    },
    data(){
      return{
        cities: {},
        hotCities: [],
        letter: ''
      }
    },
    methods: {
      getCityInfo(){
        axios.get('/api/city.json').then(res => {
          const data = res.data;
          console.log(data);
          if(data.ret && data.data){
            this.cities = data.data.cities;
            this.hotCities = data.data.hotCities
          }
        })
      },
      handleChange(letter){
        // console.log(letter)
        this.letter = letter;
      }
    },
    mounted () {
      this.getCityInfo()
    }
  }
</script>

<style scoped>

</style>
